package com.joolun.web.controller.scrm;

import java.util.List;

import com.joolun.weixin.service.IScrmJobGroupService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.joolun.common.annotation.Log;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.common.enums.BusinessType;
import com.joolun.system.domain.ScrmJobGroup;
import com.joolun.common.utils.poi.ExcelUtil;
import com.joolun.common.core.page.TableDataInfo;

/**
 * 职能分组Controller
 * 
 * @author joolun
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/scrm/jobGroup")
public class ScrmJobGroupController extends BaseController
{
    @Autowired
    private IScrmJobGroupService scrmJobGroupService;

    /**
     * 查询职能分组列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ScrmJobGroup scrmJobGroup)
    {
        startPage();
        List<ScrmJobGroup> list = scrmJobGroupService.selectScrmJobGroupList(scrmJobGroup);
        return getDataTable(list);
    }

    /**
     * 导出职能分组列表
     */
    @PreAuthorize("@ss.hasPermi('scrm:group:export')")
    @Log(title = "职能分组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScrmJobGroup scrmJobGroup)
    {
        List<ScrmJobGroup> list = scrmJobGroupService.selectScrmJobGroupList(scrmJobGroup);
        ExcelUtil<ScrmJobGroup> util = new ExcelUtil<ScrmJobGroup>(ScrmJobGroup.class);
        util.exportExcel(response, list, "职能分组数据");
    }

    /**
     * 获取职能分组详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scrmJobGroupService.selectScrmJobGroupById(id));
    }

    /**
     * 新增职能分组
     */
    @PreAuthorize("@ss.hasPermi('scrm:group:add')")
    @Log(title = "职能分组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScrmJobGroup scrmJobGroup)
    {
        scrmJobGroup.setCreateBy(getUsername());
        return toAjax(scrmJobGroupService.insertScrmJobGroup(scrmJobGroup));
    }

    /**
     * 修改职能分组
     */
    @PreAuthorize("@ss.hasPermi('scrm:group:edit')")
    @Log(title = "职能分组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScrmJobGroup scrmJobGroup)
    {
        scrmJobGroup.setCreateBy(getUsername());
        return toAjax(scrmJobGroupService.updateScrmJobGroup(scrmJobGroup));
    }

    /**
     * 删除职能分组
     */
    @PreAuthorize("@ss.hasPermi('scrm:group:remove')")
    @Log(title = "职能分组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scrmJobGroupService.deleteScrmJobGroupByIds(ids));
    }
}
